package bank;

public class _38CountAndSay {
    public static String countAndSay(int n) {
        if (n == 1){
            return "1";
        }
        String last = countAndSay(n-1);
        StringBuilder res = new StringBuilder();
        for (int i = 0;i < last.length();i++){
            int num = 1;
            while (i < last.length() - 1 && last.charAt(i) == last.charAt(i+1)){
                num++;
                i++;
            }
            res.append(num);
            res.append(last.charAt(i));
        }
        return res.toString();
    }
}
